package com.oneday.nuo.base.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**用来自动设置数据库字段的类
 * @author liushuai
 * @date 2020/8/20 20:26
 */

@Component
public class NuoMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
       this.setFieldValByName("createDate",new Date(),metaObject);
       this.setFieldValByName("createUser", String.valueOf(CurrentUser.getCurrentUser().getId()),metaObject);
       this.setFieldValByName("updateDate",new Date(),metaObject);
       this.setFieldValByName("updateUser",String.valueOf(CurrentUser.getCurrentUser().getId()),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateDate",new Date(),metaObject);
        this.setFieldValByName("updateUser",String.valueOf(CurrentUser.getCurrentUser().getId()),metaObject);

    }
}
